$(function  () {
    $('#submit').on('tap', function () {
        //1、获取表单数据并序列化
        //序列化之后的格式：“key1=val1&key2=val2”
        // var data = $('form').serialize().3
        // // 2、标准化
        // // 标准化之后的格式{"key1":"val1","key2":"val2"}
        // var dataObj = CT.serialize2object(data)
        var username = $.trim($('[name="username"]').val())
        var password = $.trim($('[name="password"]').val())
        //3、校验
        if (!username) {
            mui.toast('请输入用户名')
            return false
        }
        if (!password) {
            mui.toast('请输入密码')
            return false
        }
        console.log(username)
        console.log(password)
        $.ajax({
            url: '/user/login',
            type: 'post',
            data: {
                username: username,
                password: password
            },
            dataType: 'json',
            success: function (data) {
               if (data.success == true) {
                   //业务成功
                   // 如果成功，根据地址跳转，没成功就根据默认地址跳转
                   var returnUrl = location.search.replace('?returnUrl=','')
                   if (returnUrl) {
                       location.href = returnUrl
                   } else {
                       location.href = 'user.html'
                   }
               } else {
                    //业务不成功
                   mui.toast(data.message)
               }

            }
        })
    })

})